﻿<UserControl x:Class="TreeBuilder.TreeNode"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:tb="clr-namespace:TreeBuilder"
             mc:Ignorable="d"
             Panel.ZIndex="2"
             Name="Root"
             Focusable="True"
             GotFocus="Node_GotFocus"
             LostFocus="Node_LostFocus"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Nodes/NodeResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
        <WrapPanel 
            Name="ButtonPanel" Orientation="Horizontal"
            Background="{x:Static SystemColors.ControlBrush}"
            ItemWidth="25"
            ItemHeight="25"
            HorizontalAlignment="Center"
            Width="75"
            Height="50"
            Visibility="Hidden"
            MouseLeave="ButtonPanel_MouseLeave"
            Panel.ZIndex="3"
            >
            <Button x:Name="LineButton" Style="{StaticResource ButtonStyle}" Content="{StaticResource LineImage}"
                    Click="LineButton_Click" Focusable="False"
                    />
            <Button x:Name="ArrowButton" Style="{StaticResource ButtonStyle}" Content="{StaticResource ArrowImage}"
                    Click="ArrowButton_Click" Focusable="False"/>
            <Button x:Name="TriangleButton" Style="{StaticResource ButtonStyle}" Content="{StaticResource TriangleImage}"
                    Click="TriangleButton_Click" Focusable="False"/>
            <Button x:Name="DeleteButton" 
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource DeleteImage}"
                    Click="DeleteButton_Click" Focusable="False"
                    />
            <tb:DragButton x:Name="DragButton"
                PreviewMouseDown="DragButton_MouseDown"
                Focusable="True"
                />
            <Button x:Name="FontButton" PreviewMouseDown="FontButton_MouseUp"
                    Style="{StaticResource ButtonStyle}" Content="{StaticResource FontImage}" Focusable="False"/>
        </WrapPanel>
        <Grid>
            <tb:TreeNodeBox
                x:Name="TextBox"
                TextChanged="TextBox_TextChanged" 
                Text="Enter the text"
                Style="{StaticResource NodeBoxStyle}"
                PreviewDragOver="TextBox_DragOver"
                PreviewDrop="TextBox_PreviewDrop"
                PreviewMouseLeftButtonDown="TextBox_PreviewMouseLeftButtonDown"
                BorderBrush="LightGray"
                Padding="0"
                Margin="0"
                GotKeyboardFocus="TextBox_OnGotKeyboardFocus"
                LostKeyboardFocus="TextBox_OnLostKeyboardFocus"
                HorizontalAlignment="Center"
                SizeChanged="TextBox_SizeChanged"
                Loaded="TextBox_OnLoaded"
                Grid.Row="1"
                IsBeingPrinted="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=tb:TreeNode, AncestorLevel=1}, Path=IsBeingPrinted}"
                IsBeingLinked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=tb:TreeNode, AncestorLevel=1}, Path=IsBeingLinked}"
                >
                <tb:TreeNodeBox.ContextMenu>
                    <ContextMenu Closed="ContextMenu_Closed" Opened="ContextMenu_Opened">
                        <MenuItem>
                            <MenuItem.Header>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" MinWidth="150">
                                    <TextBlock Text="Upper index: " VerticalAlignment="Center"/>
                                    <TextBox x:Name="UpperIndexBox" Width="60" Height="25"/>
                                    <Button 
                                        x:Name="UpperIndexFontBtn" Click="UpperIndexFontBtn_Click" Width="{Binding Height}" Height="25"
                                        Style="{StaticResource ButtonStyle}" VerticalAlignment="Center">
                                        <Image Source="pack://application:,,,/Icons/font.png"/>
                                    </Button>
                                </StackPanel>
                            </MenuItem.Header>
                        </MenuItem>
                        <MenuItem>
                            <MenuItem.Header>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                    <TextBlock Text="Lower index: " VerticalAlignment="Center"/>
                                    <TextBox x:Name="LowerIndexBox" Width="60" Height="25" VerticalAlignment="Center"/>
                                    <Button 
                                        x:Name="LowerIndexFontBtn" Click="LowerIndexFontBtn_Click" Height="{Binding Height}" Width="25"
                                        Style="{StaticResource ButtonStyle}"
                                        VerticalAlignment="Center">
                                        <Image Source="pack://application:,,,/Icons/font.png"/>
                                    </Button>
                                </StackPanel>
                            </MenuItem.Header>
                        </MenuItem>
                    </ContextMenu>
                </tb:TreeNodeBox.ContextMenu>
            </tb:TreeNodeBox>
        </Grid>
    </StackPanel>
</UserControl>
